//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
let extension = {
    components: {//动态扩充组件或组件路径
        //表单header、content、footer对应位置扩充的组件
        gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
        gridBody: '',
        gridFooter: '',
        //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
        modelHeader: '',
        modelBody: '',
        modelFooter: ''
    },
    buttons: { view: [], box: [], detail: [] },//扩展的按钮
    methods: {//事件扩展
        getOption (field) {
            let option;
            this.editFormOptions.forEach(x => {
                x.forEach(item => {
                    if (item.field == field) {
                        option = item;
                    }
                })
            })
            return option;
        },
        onInit () {
            this.boxOptions.width = 800;
            this.boxOptions.height = 400;
            let isAuto = this.getOption('isAuto')
            let tradeTerm = this.getOption('tradeTerm')
            let cWhere = this.getOption('cWhere')
            let isJoin = this.getOption('isJoin')
            let isMoney = this.getOption('isMoney')
            let isRelation = this.getOption('isRelation')
            isAuto.onChange = (n) => {
                if (n == 0) {
                    isJoin.hidden = true
                    isMoney.hidden = true
                    isRelation.hidden = true
                    tradeTerm.hidden = true
                    cWhere.hidden = true
                } else {
                    isJoin.hidden = false
                    isMoney.hidden = false
                    isRelation.hidden = false
                    tradeTerm.hidden = false
                    cWhere.hidden = false
                }
            }
        },
        rowClick ({ row, column, event }) {
            this.$refs.table.$refs.table.toggleRowSelection(row);
            return true;
        },
        modelOpenAfter (row) {
            let isJoin = this.getOption('isJoin')
            let isMoney = this.getOption('isMoney')
            let isRelation = this.getOption('isRelation')
            let tradeTerm = this.getOption('tradeTerm')
            let cWhere = this.getOption('cWhere')
            if (this.currentAction == 'Add') {
                isJoin.hidden = true
                isMoney.hidden = true
                isRelation.hidden = true
                tradeTerm.hidden = true
                cWhere.hidden = true
            } else {
                if (row.isAuto == 0) {
                    isJoin.hidden = true
                    isMoney.hidden = true
                    isRelation.hidden = true
                    tradeTerm.hidden = true
                    cWhere.hidden = true
                } else {
                    isJoin.hidden = false
                    isMoney.hidden = false
                    isRelation.hidden = false
                    tradeTerm.hidden = false
                    cWhere.hidden = false
                    this.editFormFields.isJoin = row.isJoin == 1 ? true : false
                    this.editFormFields.isMoney = row.isMoney == 1 ? true : false
                    this.editFormFields.isRelation = row.isRelation == 1 ? true : false
                }
            }
        },
        addBefore (formData) {
            return this.setStatus(formData)
        },
        updateBefore (formData) {
            return this.setStatus(formData)
        },
        setStatus (formData) {
            formData.mainData.isJoin = formData.mainData.isJoin == true ? 1 : 0
            formData.mainData.isMoney = formData.mainData.isMoney == true ? 1 : 0
            formData.mainData.isRelation = formData.mainData.isRelation == true ? 1 : 0
            return true
        },
    }
};
export default extension;